﻿package mortal.game.view.closedBetaGiftBag.renderer
{
    import Message.DB.Tables.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.common.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.mvc.core.*;

    public class ClosedBetaGiftBagRenderer extends GCellRenderer
    {
        private var _bg:GBitmap;
        private var _title:GBitmap;
        private var _tip:GTextFiled;
        private var _itemBg:GBitmap;
        private var _item:BaseItem;
        private var _getBtn:GLoadingButton;
        private var _lv:BitmapNumberText;
        private var _award:BitmapNumberText;
        private var _state:GBitmap;
        private var _isLoadCompl:Boolean = false;

        public function ClosedBetaGiftBagRenderer()
        {
            return;
        }// end function

        private function onClickGetBtn(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ClosedBetaGiftBagGetReward, this.itemData.level));
            return;
        }// end function

        private function get itemData() : TLevelRewardConfig
        {
            return data as TLevelRewardConfig;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._award.text = this.itemData.diamondNum.toString();
            this._lv.text = this.itemData.level.toString();
            this._tip.toolTipData = Language.getStringByParam(90400, this.itemData.diamondNum);
            if (int(Cache.instance.closedBetaGiftBag.rewardInfo[this.itemData.level]) == 0)
            {
                this.addChild(this._getBtn);
                DisplayUtil.removeMe(this._state);
                this._getBtn.filterEnabled = Cache.instance.role.entityInfo.level >= this.itemData.level;
            }
            else
            {
                this.addChild(this._state);
                DisplayUtil.removeMe(this._getBtn);
            }
            return;
        }// end function

        private function onResCompl() : void
        {
            this._isLoadCompl = true;
            this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.ClosedBetaGiftBagItemBg1);
            this._itemBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.ClosedBetaGiftBagItem);
            this._title.bitmapData = GlobalClass.getBitmapData(ImagesConst.ClosedBetaGiftBagTxt);
            this._state.bitmapData = GlobalClass.getBitmapData(ImagesConst.ClosedBetaGiftBagState);
            pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.ClosedBetaGiftBagTxt1, 50, 30, this));
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gBitmap("", 0, 0, this);
            this._title = UIFactory.gBitmap("", 24, 5, this);
            this._tip = UIFactory.gTextField("", 35, 64, 60, 60, this);
            this._getBtn = UIFactory.gLoadingButton(ResFileConst.RectGetBtn, 31, 136, 68, 25, this);
            this._lv = UIFactory.bitmapNumberText(66, 5, "ClosedBetaGiftBagNum.png", 18, 18, -8, this);
            this._award = UIFactory.bitmapNumberText(51, 31, "ClosedBetaGiftBagItemNum.png", 18, 18, -8, this, 10, BitmapNumberText.Right);
            this._state = UIFactory.gBitmap("", 31, 105, this);
            this._item = UICompomentPool.getUICompoment(BaseItem);
            this.addChild(this._item);
            this._item.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            this._item.x = 29;
            this._item.y = 57;
            this._itemBg = UIFactory.gBitmap("", 35, 64, this);
            pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.LockIcon, 34, 65, this));
            this._getBtn.configEventListener(MouseEvent.CLICK, this.onClickGetBtn);
            Dispatcher.addEventListener(EventName.ClosedBetaGiftBagFlyToPack, this.onClosedBetaGiftBagFlyToPack);
            LoaderHelp.addResCallBack(ResFileConst.closedBetaGiftBag, this.onResCompl);
            return;
        }// end function

        private function onClosedBetaGiftBagFlyToPack(event:DataEvent) : void
        {
            if (isDisposed)
            {
                return;
            }
            if (!this._isLoadCompl)
            {
                return;
            }
            var _loc_2:* = event.data as int;
            if (_loc_2 != this.itemData.level)
            {
                return;
            }
            var _loc_3:* = this._item.localToGlobal(new Point(0, 0));
            FlyToNavbarTool.flyToBackPack(this._itemBg.bitmapData, _loc_3);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._isLoadCompl = false;
            LoaderHelp.removeResEvent(ResFileConst.closedBetaGiftBag, this.onResCompl);
            Dispatcher.removeEventListener(EventName.ClosedBetaGiftBagFlyToPack, this.onClosedBetaGiftBagFlyToPack);
            this._bg.dispose(param1);
            this._tip.dispose(param1);
            this._title.dispose(param1);
            this._item.dispose(param1);
            this._itemBg.dispose(param1);
            this._award.dispose(param1);
            this._getBtn.dispose(param1);
            this._lv.dispose(param1);
            this._state.dispose(param1);
            return;
        }// end function

    }
}
